package com.course.testng.parameters;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.lang.reflect.Method;

public class DataProviderTest {

    @Test(dataProvider = "data")
    public void testDataProvider(String name, int age) {
        System.out.println("name = " + name + "; age= " + age);

    }

    @DataProvider(name = "data")
    public Object[][] providerData() {

        return new Object[][]{
                {"张三", 18},
                {"李四", 25},
                {"王五", 30},
        };
    }

    @Test(dataProvider = "methodData")
    public void test1(String name, int age) {
        System.out.println("test1方法中的：" + name + age);
    }

    @Test(dataProvider = "methodData")
    public void test2(String name, int age) {
        System.out.println("test2方法中的：" + name + age);
    }

    @DataProvider(name = "methodData")
    public Object[][] methodDataTest(Method method) {
        Object[][] result = null;

        if (method.getName().equals("test1")) {
            result = new Object[][]{
                    {"张三", 18},
                    {"李四", 28},
            };
        } else if (method.getName().equals("test2")) {
            result = new Object[][]{
                    {"王五", 35},
                    {"赵六", 27},
            };
        }

        return result;
    }
}
